$(function(){
	showCondition(true);
	// 初始化滑块 ---开始
	$("[role='tabpanel']").each(function(i,n){
		 $(n).addClass('testCon');
	});
	$("#"+tabId+" #benchmarkSlider .filterSlider").slider({
		min: 1, max: 99 , range: false, value: 20,
	    reversed : false
	});
	$("#"+tabId+" #stdDeviationSlider .filterSlider").slider({
		min: 0, max: 5 , range: false, value: 1,
	    reversed : false
	});
	$("[role='tabpanel']").each(function(i,n){
		 $(n).removeClass('testCon');
	});
	$("#"+tabId+" .slider").css("display","block");
	// 初始化滑块 ---结束
	// 隐藏滑块背景
	$("#" + tabId + " .sliderBackgroud").css("display","none") ;
	var param = paramTabPage[tabId]= $("#tabContent > .tab-pane.active").data() ;
	var drgCode = $("#tabContent > .tab-pane.active").data().pardrgCode ;

	// 标题
	$("#"+ tabId + " #header").html(param.desc) ;
	$("#"+ tabId + " .titleMod1").html(param.pardrgCode+"指标") ;
	// 定义加载对象。 divId、指标code、 指标名称、  数据data
	var caseCnt = {"id":"caseCnt","title":"病例数","quotas":
		[{"code":"PayGroupCnt","title":"入组病例数"},{"code":"PayGroupOverFeeCnt","title":"费用超标病例数","link":"payGroupCaseList"},{"code":"PayGroupOverFeeCnt|PayGroupCnt","title":"费用超标病例率（%）"}],"data":{}} ;
	var drgFeeEff = {"id":"drgFeeEff","title":"病组费用效率","quotas":
		[{"code":"AvgFee","title":"次均费用"},{"code":"AvgFee|","title":"次均费用标杆"},{"code":"PayGroupFeeEff","title":"费用消耗指数"}],"data":{}} ;
	var caseFee = {"id":"caseFee","title":"病例费用","quotas": [{"code":"TotalFee","title":"总费用"}],"data":{}} ;
	// 五大类费用指标
	var fiveCategoriesFeeQuotas = ["TechFee","NursFee","MedFee","ManageFee","DrugMaterFee"] ;
	// 加载全院指标-病例数
	loadDataPayGroup(caseCnt,loadCntDrgDiv,{"monitorType":"drgs","pardrgCode":drgCode}) ;
	// 加载全院指标-病组费用效率
	loadDataPayGroup(drgFeeEff,loadCntDrgDiv,{"monitorType":"drgs","pardrgCode":drgCode,"isGetCc":"1","pType":"1","compareType":"std","msCode":"std_paygroup"}) ;
	// 全院指标 - 病例费用
	findFeeExtremal() ;
	
	// 病组费用构成及对比
	findDiffCompareTypeFee() ;
	// 病例分布特征
	findCaseDistributionFeature();
	// 初始化加载标杆法区间划分
	var sliderValBench = 20  ;
	queryCostStructureBenchmarking(drgCode,sliderValBench) ;
	$("#"+tabId+" #benchmarkSlider .filterSlider").on("slideStop",function(slideEvt) {
		sliderValBench = slideEvt.value ;
		queryCostStructureBenchmarking(drgCode,sliderValBench) ;
	});
	
	// 初始化标差法区间划分
	var sliderValStdDev = 1  ;
	$("#"+tabId+" #stdDeviationSlider .filterSlider").on("slideStop",function(slideEvt) {
		sliderValStdDev = slideEvt.value ;
		queryCostStructureStdDev(drgCode,sliderValStdDev) ;
	});
	
	$("#" +tabId+" #mdcallhosp-ul").on("click","li",function() {
		var href = $(this).children("a").attr("href") ;
		if(href == "#stdDeviation") {
			// 标差法区间划分
			queryCostStructureStdDev(drgCode,sliderValStdDev);
		} else {
			// 标杆法区间划分
			queryCostStructureBenchmarking(drgCode,sliderValBench) ;
		}
	})
}) 


/**
 * 标杆法区间划分
 * @
 * @void
 * @ Discription:
 * @paygroupAnalysis_dep.js
 */
function queryCostStructureBenchmarking(drgCode,sliderVal) {
	var sliderVal2 = (100+sliderVal)/100 ;
	var param=drgUI.setAjaxData(tabId);
	param.pType = "1" ;
	param.isGetCc = "0" ;
	param.monitorType = "hosp" ;
	param.sliderVal = sliderVal2 ;
	param.pardrgCode = drgCode ;
	
	$.post(contextPath + "/payGroup/queryCostStructureBenchmarking.dhc", param ).done(function(data) {
		// 画病例区间分布-饼图
		var caseDis = [];// 病例分布
		var data = data.data ;
		if(data[3]) {
			caseDis.push({name:"未超标病例",value: data[3].INCNT});
		}
		if(data[2]) {
			caseDis.push({name:"超标"+sliderVal+"%及以上病例",value:data[2].INCNT});
		}
		if(data[1]) {
			caseDis.push({name:"超标"+sliderVal+"%及以内病例",value:data[1].INCNT});
		}
		var echartConfig = {"showLabel":false,"showLabelLine":false,radius:[0,"60%"],legendItemGap:5}
		pieCharts($("#"+tabId+" #benchCaseIntervalEch"), caseDis, drgCode+"病组病例区间分布图", paramTabPage[tabId].desc,echartConfig);
		// 病例区间分布表
		var title = ["全部病例","超标"+sliderVal+"%及以上病例","超标"+sliderVal+"%以内病例","未超标病例"] ;
		// 右侧表格数据处理
		processTableData (data,title) ;
		var columns=[
		               	{"data": "TITLE","title":"区间内病例类型"},
		               	{"data": "FEEINTERVEL","title":"费用区间范围" },
		               	{"data": "INCNT","title":"病例数",
		               		"render":function(obj,type,full) {
		               			if(Number(formatNumPayGroup(full.INCNT,0))) {
			               			return "<a intervel=\""+full.INTERVEL+"\" title=\""+full.TITLE+"\" sliderVal=\""+sliderVal+"\" class=\"drgsIncnt\">"+formatNumPayGroup(full.INCNT,0)+"</a>" ;
		               			} else {
			               			return formatNumPayGroup(full.INCNT,0) ;
		               			}
			               	}
		               	},
		               	{"data": "INCNTR","title":"病例数<br/>占比(%)",
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.INCNTR,2);
		           			}
		               	},
		           		{"data": "AVGFEE","title":"次均费用",
		               		"render": function(obj, type, full) {
		               			if(full.AVGFEE >full.AVGFEESTD)
	               				{
		               				return "<span style = 'color:red'>"+formatNumPayGroup(full.AVGFEE,2)+"</span>";
	               				}
		               			return formatNumPayGroup(full.AVGFEE,2);
		           			}
	           			},
		           		{"data": "AVGFEESTD","title":"次均费用标杆",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(data[4].AVGFEESTD,2) ;
		           			}
	           			},
		           		{"data": "PROFIT","title":"预计结余(万元)",
		           			"render": function(obj, type, full) {
		               			if(full.PROFIT < 0 )
	               				{
		               				return "<span style = 'color:red'>"+full.PROFIT+"</span>";
	               				}
		               			return full.PROFIT;
		           			}
		           		},
		           		{"data": "OPERATION","title":"操作",
		           			"render": function(obj, type, full) {
		           				if(full.INTERVEL >0&&full.INCNT>0) {
		           					return "<a intervel=\""+full.INTERVEL+"\" title=\""+full.TITLE+"\" sliderVal=\""+sliderVal+"\" class=\"depA\">科室</a>" ;
		           				}
		           			}
		           		}
		           	];
		var target = data.slice(4,5)[0] ;
		var tableData = data.slice(0,4) ;
		var paramsDataTables={searching:false,lengthChange:false,ordering:false,stateSave:true,info:false,paging:false,tableTitle: "病例区间分布表",columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
		$("#"+tabId+" #benchCaseInterval").empty();
		$("#"+tabId+" #benchCaseInterval").append('<table id="benchCaseIntervalTab" class="table"><caption><h5>病例区间分布表</h5></caption></table>') ;
		$("#"+tabId+" #benchCaseIntervalTab").dataTableBasic(columns,tableData,paramsDataTables) ;
		$("#"+tabId+" #benchCaseIntervalTab").on("click",".depA",function() {
			var param = drgUI.setAjaxData(tabId)
			param.pType = "1" ;
			param.pardrgCode = drgCode ;
			param.sliderVal = $(this).attr("sliderVal") ;
			param.intervel = $(this).attr("intervel") ;
			param.methodType = "1" ;
			param.target = target;
			var title = $(this).attr("title") ;
			var pid = param.sliderVal+param.intervel+param.methodType+param.target ;
			openTab("/pages/paygroup/paygroupAnalysis_dep_overproof.jsp", title + "病组费用分析", "paygroupAnalysis_dep_overproof"+pid , "paygroupAnalysis_dep_overproof"+pid, param);
		})
		//点击病例数进去
		$("#"+tabId+" #benchCaseIntervalTab").on("click",".drgsIncnt",function() {
			var param = drgUI.setAjaxData(tabId);
			param.pType = "1" ;
			param.pardrgCode = drgCode ;
			param.sliderVal = sliderVal ;
			param.intervel = $(this).attr("intervel") ;
			param.methodType="1";
			var title = $(this).attr("title") ;
			openTab('/pages/paygroup/paygroup_drgscaselist.jsp', drgCode + "|病例明细", "paygroup_drgscaselist"+param.intervel+param.methodType+sliderVal , "paygroup_drgscaselist"+param.intervel+param.methodType+sliderVal, param);
		})
		// 病例费用对比
		var y = [] ;
		var dataE = [] ;
		var titleE = ["全部病例","超标"+sliderVal+"%以上","超标"+sliderVal+"%以内","未超标病例","标杆值"] ;
		for(var o in data) {
			dataE.push(data[o].AVGFEE);
			y.push(titleE[o]) ;
		}
		// 图例边距和名称
		var legend = {"x":"40%","y":50, "data": ["次均费用"] } ;
		var param = {"title":drgCode + "病组不同区间内病例次均费用对比图","subtitle":paramTabPage[tabId].desc,"legend":legend,"series":[{"data":dataE,"name":"次均费用"}],"y":{"data":y}};
		param.gridTop = '80' ;
		// 病例费用对比
		drawPayGroupBarChart("avgFeeBenchEch",param) ;

		// 病例费用构成及对比
		var titleER = ["全部病例","超标"+sliderVal+"%以上","超标"+sliderVal+"%以内","未超标病例","标杆值"] ;
		var yER = [] ;
		var techFee = [] ;
		var manageFee = [] ;
		var medFee = [] ;
		var nursFee =[] ;
		var drugMaterCost = [] ;
		var legend = {"x":0,"y":50, "data": ["医疗费用", "护理费用","管理费用","医技费用","药品耗材费用"] } ;
		var param = {"title":drgCode + "病组不同区间内病例费用构成及对比图","subtitle":paramTabPage[tabId].desc,"legend":legend,"series":[
		                                                              {"name":"医疗费用","type":"bar","data":medFee},
		                                                              {"name":"护理费用","type":"bar","data":nursFee},
		                                                              {"name":"管理费用","type":"bar","data":manageFee},
		                                                              {"name":"医技费用","type":"bar","data":techFee},
		                                                              {"name":"药品耗材费用","type":"bar","data":drugMaterCost}
		                                                              ],"y":{"data":yER}};
		
		for(var o in data) {
			// 如果有该区间，即该区间有病例分布
			if(data[o]) {
				var i = data[o].INTERVEL ;
				techFee.push(data[i].TECHFEE) ;
				manageFee.push(data[i].MANAGEFEE) ;
				medFee.push(data[i].MEDFEE) ;
				nursFee.push(data[i].NURSFEE) ;
				drugMaterCost.push(data[i].DRUGMATERFEE) ;	
				yER.push(titleER[i]) ;
			}
		}
//		 病组费用构成
		param.gridTop = '80' ;
		drawPayGroupBarChart("avgFeePortionBenchEch",param,null,"stackbar") ;
		// 不同区间内病例费用构成 对比表格
		var columns=[
		               	{"data": "desc","title":"区间内病例类型",
		               		"render": function(obj, type, full) {
		           				return titleER[full.INTERVEL] ;
		           			}	
		               	},
		               	{"data": "INCNT","title":"病例数",
		               		"render":function(obj,type,full){
			               		if(full.INCNT>0&&full.INTERVEL!=4){
			               			return "<a intervel=\""+full.INTERVEL+"\" title=\""+full.TITLE+"\" sliderVal=\""+sliderVal+"\" class=\"drgsIncntT\">"+full.INCNT+"</a>" ;
			               		} else if(full.INTERVEL!=4) {
			               			return full.INCNT ;
			               		} else {
			               			return "-" ;
			               		}
			               	}	
		               	},
		               	{"data": "AVGFEE","title":"次均费用" ,
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.AVGFEE,2) ;
		           			}
		               	},
		           		{"data": "DRUGCOST","title":"药品费用",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.DRUGCOST,2) ;
		           			}
		               	},
		           		{"data": "DRUGCOSTR","title":"药占比(%)",
		           			"render": function(obj, type, full) {
		           				if(full.AVGFEE) {
		           					return formatNumPayGroup((full.DRUGCOST/full.AVGFEE)*100,2);
		           				}
		           			}	
		           		},
		           		{"data": "AVGDAYS","title":"平均住院日",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.AVGDAYS,2) ;
		           			}
		           		},
		           		{"data": "MEDFEE","title":"医疗费用",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.MEDFEE,2) ;
		           			}
		           		},
		           		{"data": "NURSFEE","title":"护理费用",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.NURSFEE,2) ;
		           			}
		           		},
		           		{"data": "MANAGEFEE","title":"管理费用",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.MANAGEFEE,2) ;
		           			}
		           		},
		           		{"data": "TECHFEE","title":"医技费用",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.TECHFEE,2) ;
		           			}
		           		},
		           		{"data": "DRUGMATERFEE","title":"药品耗材费用",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.DRUGMATERFEE,2) ;
		           			}
		           		} ,
		           		{"data": "operation","title":"操作",
		           			"render": function(obj, type, full,meta) {
		           				if(meta.row>0)
	           					{
		           					return "<a data-rowindex='"+meta.row+"' class = 'costStructure'>费用构成</a>" ;
	           					}
		           			}
		           		}
	  ];
		// 标杆病例数 ——
		if(data[4]) {
			data[4].INCNT = "——" ;
		}
		// 将标杆值放在第一行
		data.unshift(data.pop()) ;
		var paramsDataTables={searching:false,lengthChange:false,ordering:false,stateSave:true,info:false,paging:false,tableTitle: drgCode + "病组次均费用、费用构成及对比情况表",columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
		var table = $("#"+tabId+" #feeCompareBench").dataTableBasic(columns,data,paramsDataTables) ;
		$("#"+tabId+" #feeCompareBench_wrapper caption").html("<h5>"+drgCode + "病组次均费用、费用构成及对比情况表" +"</h5>") ;
		
		$("#"+tabId+" #feeCompareBench tbody td").on("click",".costStructure",function(){
			var index = $(this).attr("data-rowindex");
	    	var a = table.row( index ).data();//本期|同期|上期
	    	var b = table.row(0).data();//标杆
	    	var c = ["TITLE","MEDFEE","NURSFEE","MANAGEFEE","TECHFEE","DRUGMATERFEE","AVGFEE"];
	    	costStructure(a,b,c);
		})
		//点击病例数进去
		$("#"+tabId+" #feeCompareBench tbody td").on("click",".drgsIncntT",function() {
			var param = drgUI.setAjaxData(tabId);
			param.pType = "1" ;
			param.pardrgCode = drgCode ;
			param.sliderVal = sliderVal ;
			param.intervel = $(this).attr("intervel") ;
			param.methodType="1";
			var title = $(this).attr("title") ;
			openTab('/pages/paygroup/paygroup_drgscaselist.jsp', drgCode + "|病例明细", "paygroup_drgscaselist"+param.intervel+param.methodType+sliderVal+drgCode , "paygroup_drgscaselist"+param.intervel+param.methodType+sliderVal, param);
		})
		
		//超标颜色变红
		for(var c = 3;c<=11;c++)
		{//从第3列 到第11列 (开始为1)
			//标杆行
			var tv = $("#"+tabId+" #feeCompareBench tr:nth-child("+1+") td:nth-child("+c+")").text();//标杆值
			for(var r=1;r<=5;r++)
			{//从第1行 到第5行 (开始为1)
				if(r==1)
				{
					continue;//标杆行
				}
				var cv = $("#"+tabId+" #feeCompareBench tr:nth-child("+r+") td:nth-child("+c+")").text();//列值
				if(transformFloat(cv)>transformFloat(tv))
				{
					$("#"+tabId+" #feeCompareBench tr:nth-child("+r+") td:nth-child("+c+")").css("color","red");
				}
			}
		}
		
	})
}

//付费病组病例明细
function payGroupCaseList()
{
	var param = drgUI.setAjaxData(tabId);
	param.pType = "1" ;
	param.sliderVal = "1" ;//超标倍数
	param.intervel = "1" ;//超标n% 以上的
	param.methodType="1";//超标杆
	openTab('/pages/paygroup/paygroup_drgscaselist.jsp', param.pardrgCode + "|病例明细", "paygroup_drgscaselist"+param.intervel+param.methodType+param.sliderVal , "paygroup_drgscaselist"+param.intervel+param.methodType+param.sliderVal, param);
}
/**
 * 
 * @
 * @void
 * @ Discription: 标差法划分区间
 * @paygroupAnalysis_dep.js
 */
function queryCostStructureStdDev(drgCode,sliderVal) {
	var param=drgUI.setAjaxData(tabId);
	param.pType = "1" ;
	param.isGetCc = "0" ;
	param.monitorType = "hosp" ;
	param.sliderVal = sliderVal ;
	param.pardrgCode = drgCode ;
	$.post(contextPath + "/payGroup/queryCostStructureStdDev.dhc",param).done(function(data) {
		// 画病例区间分布-饼图
		var caseDis = [];// 病例分布
		var data = data.data ;
		caseDis.push({name:"未超标病例",value:data[3].INCNT});
		caseDis.push({name:"超出"+sliderVal+"倍及以内标准差病例",value:data[2].INCNT});
		caseDis.push({name:"超出"+sliderVal+"倍及以上标准差病例",value:data[1].INCNT});
		var echartConfig = {"showLabel":false,"showLabelLine":false,radius:[0,"60%"],legendItemGap:5};
		pieCharts($("#"+tabId+" #drgAvgFeeStdDevEch"), caseDis, drgCode + "病组下病例区间分布图", paramTabPage[tabId].desc,echartConfig);
		// 病例区间分布表
		var title = ["全部病例","超出"+sliderVal+"倍及以上标准差病例","超出"+sliderVal+"倍及以内标准差病例","未超标病例"] ;
		// 右侧表格数据处理
		processTableData (data,title) ;
		var columns=[
		               	{"data": "TITLE","title":"区间内病例类型"},
		               	{"data": "FEEINTERVEL","title":"费用区间范围" },
		               	{"data": "INCNT","title":"病例数",
		               		"render":function(obj,type,full){
				               		if(!full.INCNT==0){
				               			return "<a intervel=\""+full.INTERVEL+"\" title=\""+full.TITLE+"\" sliderVal=\""+sliderVal+"\" class=\"drgsIncntA\">"+full.INCNT+"</a>" ;
				               		} else {
				               			return full.INCNT ;
				               		}
			               		}
		               	},
		               	{"data": "INCNTR","title":"病例数<br/>占比(%)",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.INCNTR,2) ;
		           			}
		               	},
		           		{"data": "AVGFEE","title":"次均费用",
		               		"render": function(obj, type, full) {
		               			if(full.AVGFEE >full.AVGFEESTD)
	               				{
		               				return "<span style = 'color:red'>"+formatNumPayGroup(full.AVGFEE,2)+"</span>";
	               				}
		               			return formatNumPayGroup(full.AVGFEE,2);
		           			}
		           		},
		           		{"data": "AVGFEESTD","title":"次均费用标杆" ,
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(data[4].AVGFEESTD,2) ;
		           			}
		           		},
		           		{"data": "PROFIT","title":"预计结余(万元)",
		           			"render": function(obj, type, full) {
		               			if(full.PROFIT < 0 )
	               				{
		               				return "<span style = 'color:red'>"+full.PROFIT+"</span>";
	               				}
		               			return full.PROFIT;
		           			}
		           		}
		           	];
		// 不取标杆行
		var tableData = data.slice(0,4)
		var paramsDataTables={searching:false,lengthChange:false,ordering:false,stateSave:true,info:false,paging:false,tableTitle: "病例区间分布表",columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
		$("#"+tabId+" #drgFeeStdDevEch").empty() ;
		$("#"+tabId+" #drgFeeStdDevEch").append('<table id="benchCaseIntervalDevTab" class="table"><caption><h5>病例区间分布表</h5></caption></table>') ;
		$("#"+tabId+" #benchCaseIntervalDevTab").dataTableBasic(columns,tableData,paramsDataTables) ;
		
		//点击病例数进去
		$("#"+tabId+" #benchCaseIntervalDevTab").on("click",".drgsIncntA",function() {
			var param = drgUI.setAjaxData(tabId);
			param.pType = "1" ;
			param.pardrgCode = drgCode ;
			param.sliderVal = sliderVal;
			param.intervel = $(this).attr("intervel") ;
			param.methodType="2";
			var title = $(this).attr("title") ;
			openTab('/pages/paygroup/paygroup_drgscaselist.jsp', drgCode + "|病例明细", "paygroup_drgscaselist"+param.intervel+param.methodType+sliderVal , "paygroup_drgscaselist"+param.intervel+param.methodType+sliderVal, param);
		})
		// 不同区间内病例费用对比
		var y = [] ;
		var dataE = [] ;
		var titleE = ["全部病例","超出"+sliderVal+"倍及以上标准差","超出"+sliderVal+"倍及以内标准差","未超标","标杆值"] ;
		for(var o = 0 ; o < data.length; o ++) {
			dataE.push(data[o].AVGFEE)  ;
			y.push(titleE[o]) ;
		}
		// 图例边距和名称
		var legend = {"x":"40%","y":50, "data": ["次均费用"] } ;
		var param = {"title":drgCode + "病组不同区间内病例次均费用对比图","subtitle":paramTabPage[tabId].desc,"legend":legend,"series":[{"data":dataE,"name":"次均费用"}],"y":{"data":y}};
		// 病组费用构成
		param.gridTop = '80' ;
		// 病例费用对比
		drawPayGroupBarChart("avgFeeStdDevEch",param) ;
		// 病例费用构成及对比
		var titleER = ["全部病例","超出"+sliderVal+"倍及以上标准差","超出"+sliderVal+"倍及以内标准差","未超标","标杆值"] ;
		var yER = [] ;
		var techFee = [] ;
		var manageFee = [] ;
		var medFee = [] ;
		var nursFee =[] ;
		var drugMaterCost = [] ;
		var legend = {"x":0,"y":50, "data": ["医疗费用", "护理费用","管理费用","医技费用","药品耗材费用"] } ;
		var paramER = {"title":"病组次均费用对比图","subtitle":paramTabPage[tabId].desc,"legend":legend,"series":[
		                                                              {"name":"医疗费用","type":"bar","data":medFee},
		                                                              {"name":"护理费用","type":"bar","data":nursFee},
		                                                              {"name":"管理费用","type":"bar","data":manageFee},
		                                                              {"name":"医技费用","type":"bar","data":techFee},
		                                                              {"name":"药品耗材费用","type":"bar","data":drugMaterCost}
		                                                              ],"y":{"data":yER}};
		
		for(var o in data) {
			// 如果有该区间，即该区间有病例分布
				var i = data[o].INTERVEL ;
				techFee.push(data[i].TECH) ;
				manageFee.push(data[i].MANAGE) ;
				medFee.push(data[i].MED) ;
				nursFee.push(data[i].NURS) ;
				drugMaterCost.push(data[i].DRUG) ;	
				yER.push(titleER[i]) ;
		}
//		 病组费用构成
		paramER.gridTop = '80' ;
//		 病组费用构成
		drawPayGroupBarChart("avgFeePortionStdDevEch",paramER,null,"stackbar") ;
	
// 		不同区间内病例费用构成 对比表格
		var columns=[
		               	{"data": "","title":"区间内病例类型",
		               		"render": function(obj, type, full) {
		           				return titleER[full.INTERVEL] ;
		           			}	
		               	},
		               	{"data": "INCNT","title":"病例数",
		               		"render": function(obj, type, full) {
		               			if(full.INCNT>0&&full.INTERVEL!=4){
			               			return "<a intervel=\""+full.INTERVEL+"\" title=\""+full.TITLE+"\" sliderVal=\""+sliderVal+"\" class=\"drgsIncntB\">"+full.INCNT+"</a>" ;
			               		}
		           			}	
		               	},
		               	{"data": "AVGFEE","title":"次均费用" ,
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.AVGFEE,2) ;
		           			}
		               	},
		           		{"data": "DRUGCOST","title":"药品费用",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.DRUGCOST,2) ;
		           			}
		               	},
		           		{"data": "DRUGCOSTR","title":"药占比(%)",
		           			"render": function(obj, type, full) {
		           				if(full.AVGFEE) {
		           					return ((full.DRUGCOST/full.AVGFEE)*100).toFixed(2) ;
		           				} else {
		           					return "" ;
		           				}
		           			}	
		           		},
		           		{"data": "AVGDAYS","title":"平均住院日",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.AVGDAYS,2) ;
		           			}
		           		},
		           		{"data": "MED","title":"医疗费用",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.MED,2) ;
		           			}
		           		},
		           		{"data": "NURS","title":"护理费用",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.NURS,2) ;
		           			}
		           		},
		           		{"data": "MANAGE","title":"管理费用",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.MANAGE,2) ;
		           			}
		           		},
		           		{"data": "TECH","title":"医技费用",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.TECH,2) ;
		           			}
		           		},
		           		{"data": "DRUG","title":"药品耗材费用",
		           			"render": function(obj, type, full) {
		           				return formatNumPayGroup(full.DRUG,2) ;
		           			}
		           		} ,
		           		{"data": "operation","title":"操作",
		           			"render": function(obj, type, full,meta) {
		           				if(meta.row<4&&full.INCNT>0)
	           					{
		           					return "<a data-rowindex='"+meta.row+"' class = 'costStructure'>费用构成</a>" ;
	           					}
		           			}
		           		}
	  ];
		// 标杆病例数 ——
		if(data[4]) {
			data[4].INCNT = "——" ;
		}
		var paramsDataTables={searching:false,lengthChange:false,ordering:false,stateSave:true,info:false,paging:false,tableTitle: drgCode + "病组次均费用、费用构成及对比情况表",columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
		var table = $("#"+tabId+" #feeCompareStdDev").dataTableBasic(columns,data,paramsDataTables) ;
		$("#"+tabId+" #feeCompareStdDev_wrapper caption").html("<h5>"+drgCode + "病组次均费用、费用构成及对比情况表" +"</h5>") ;

		$('#'+tabId+' #feeCompareStdDev tr').on( 'click', '.costStructure', function () {
	    	var index = $(this).attr("data-rowindex");
	    	var a = table.row( index ).data();//本期|同期|上期
	    	var b = table.row(4).data();//标杆
	    	var c = ["TITLE","MED","NURS","MANAGE","TECH","DRUG","AVGFEE"];
	    	costStructure(a,b,c);
	    } );
		//点击病例数进去
		$("#"+tabId+" #feeCompareStdDev tr").on("click",".drgsIncntB",function() {
			var param = drgUI.setAjaxData(tabId);
			param.pType = "1" ;
			param.pardrgCode = drgCode ;
			param.sliderVal = sliderVal ;
			param.intervel = $(this).attr("intervel") ;
			param.methodType="2";
			var title = $(this).attr("title") ;
			openTab('/pages/paygroup/paygroup_drgscaselist.jsp', drgCode + "|病例明细", "paygroup_drgscaselist"+param.intervel+param.methodType+sliderVal , "paygroup_drgscaselist"+param.intervel+param.methodType+sliderVal, param);
		})
		
		//超标颜色变红
		for(var c = 3;c<=11;c++)
		{//从第3列 到第11列 (开始为1)
			for(var r=1;r<=5;r++)
			{//从第1行 到第5行 (开始为1)
				if(r==5)
				{
					continue;//标杆行
				}
				var cv = $("#"+tabId+" #feeCompareStdDev tr:nth-child("+r+") td:nth-child("+c+")").text();//列值
				var tv = $("#"+tabId+" #feeCompareStdDev tr:nth-child("+5+") td:nth-child("+c+")").text();//标杆值
				if(transformFloat(cv)>transformFloat(tv))
				{
					$("#"+tabId+" #feeCompareStdDev tr:nth-child("+r+") td:nth-child("+c+")").css("color","red");
				}
			}
		}
	})
}


/**
 * 处理表格数据
 * @@param data 
 * @@param title 行标题
 * @void
 * @ Discription:
 * @paygroupAnalysis_drg.js
 */
function processTableData (data,title) {
	// 费用区间 
	for(var i = 0 ; i<4 ; i ++  ) {
		if( data[i] && i == data[i].INTERVEL ) {
			data[i].TITLE = title[i] ;
			data[i].FEEINTERVEL = obtainCaseDis(data,20,i) ;
			data[i].INCNTR = (data[i].INCNT/data[0].INCNT*100).toFixed(2) ;
			data[i].PROFIT = (data[i].AVGFEESTD - data[i].AVGFEE).toFixed(2) ;
		} else {
			// 该区间没有病例分布
			var obj = {} ;
			obj.TITLE = title[i] ;
			obj.FEEINTERVEL = obtainCaseDis(data,20,i) ;
			obj.INTERVEL = i ;
			obj.INCNTR = 0 ;
			obj.PROFIT = 0 ;
			obj.AVGFEESTD = data[4].AVGFEESTD ;
			data.splice(i,0,obj) ;
			// 移除最后一个元素
			data.pop() ;
		}
	}
}

/**
 * 获取费用区间
 * @@param data 数据
 * @@param slider 超标比例系数
 * @@param index 第几行
 * @@returns {String}
 * @String
 * @ Discription:
 * @paygroupAnalysis_drg.js
 */
function obtainCaseDis(data,slider,index) {
	var min = data[0].MINVAL ; 
	var max = data[0].MAXVAL;
	var base = data[4].AVGFEESTD ;
	var section = "" ;
	switch(index) {
		case 0: section = "["+ min+"," + max + "]" ;break;
		case 1: section = "("+((1+slider)/100*base).toFixed(2) + "," + max + "]" ; break;
		case 2: section = "("+base + "," + ((1+slider)/100*base).toFixed(2) + "]" ;break;
		case 3: section = "[" + min + "," + base + "]" ;break;
	}
	return section ;
}



// 本期：year  标杆std  上期month  同期 year cc
/**
 *  病组费用构成及对比
 */
function findDiffCompareTypeFee() {
	var drgAvgFeeEch = {"id":"drgAvgFeeEch","title":"次均费用","quotas": [{"code":"AvgFee","title":"次均费用（元）"},
	                                         						 {"code":"PayGroupCnt","title":"付费病组病例数"}
	                                         						,{"code":"PayGroupOverFeeCnt","title":"费用超标病例数"},{"code":"DrugFee","title":"药品费用(万元)"}
	                                         						,{"code":"DrugRatio","title":"药占比(%)"},{"code":"AvgDays","title":"平均住院日"}
	                                         						,{"code":"TechFee","title":"医技费"},{"code":"ManageFee","title":"管理费"}
	                                         						,{"code":"MedFee","title":"医疗费"},{"code":"NursFee","title":"护理费"}
	                                         						,{"code":"DrugMaterFee","title":"药品费"}],"data":{}} ;	
//	var compareType = ["year"] ;
	var compareType = ["year","std","month"] ;
	var param0 = paramTabPage[tabId]= $("#tabContent > .tab-pane.active").data() ;
	for(var o in compareType) {
		var param = jQuery.extend(true,{},param0);
		param.compareType = compareType[o] ;
		param.monitorType = "drgs" ;
		param.pType = "1" ;
		// 当比较值为标杆时，仅获取标杆值，不获取本期值
		if(compareType[o] == "std") {
			param.msCode = "std_paygroup" ;
			param.isGetCc = "only1" ;
		} else {
			param.isGetCc = "1" ;
		}
		loadDataPayGroup(drgAvgFeeEch,function(){
			// 当不同比较类型的数据均返回的时候
			if( drgAvgFeeEch.data.year && drgAvgFeeEch.data.std && drgAvgFeeEch.data.month  ) {
				// 当数据均返回的时候开始拼装数据
				var data = drgAvgFeeEch.data ;
				// 将五大类费用的累计值转换为平均值
				for(var i in compareType) { 
					if(compareType[i] == "std") {
						continue ;
					}
					if(data[compareType[i]][0]) {
						data[compareType[i]][0].TechFee = (data[compareType[i]][0].TechFee/data[compareType[i]][0].PayGroupCnt).toFixed(2) ;
						data[compareType[i]][0].TechFeecc = (data[compareType[i]][0].TechFeecc/data[compareType[i]][0].PayGroupCntcc).toFixed(2) ;
						data[compareType[i]][0].ManageFee = (data[compareType[i]][0].ManageFee/data[compareType[i]][0].PayGroupCnt).toFixed(2) ;
						data[compareType[i]][0].ManageFeecc = (data[compareType[i]][0].ManageFeecc/data[compareType[i]][0].PayGroupCntcc).toFixed(2) ;
						data[compareType[i]][0].MedFee = (data[compareType[i]][0].MedFee/data[compareType[i]][0].PayGroupCnt).toFixed(2) ;
						data[compareType[i]][0].MedFeecc = (data[compareType[i]][0].MedFeecc/data[compareType[i]][0].PayGroupCntcc).toFixed(2) ;
						data[compareType[i]][0].NursFee = (data[compareType[i]][0].NursFee/data[compareType[i]][0].PayGroupCnt).toFixed(2) ;
						data[compareType[i]][0].NursFeecc = (data[compareType[i]][0].NursFeecc/data[compareType[i]][0].PayGroupCntcc).toFixed(2) ;
						data[compareType[i]][0].DrugMaterFee = (data[compareType[i]][0].DrugMaterFee/data[compareType[i]][0].PayGroupCnt).toFixed(2) ;
						data[compareType[i]][0].DrugMaterFeecc = (data[compareType[i]][0].DrugMaterFeecc/data[compareType[i]][0].PayGroupCntcc).toFixed(2) ;
					}
				}
				var y = [] ;
				var dataE = [] ;
				if(data.year[0]) {
					dataE.push(data.year[0].AvgFeecc) ;
					y.push("同期值") ;
				}
				if(data.month[0]) { 
					dataE.push(data.month[0].AvgFeecc) ;
					y.push("上期值") ;
				}
				if(data.std[0]) {
					dataE.push(data.std[0].AvgFeecc) ;
					y.push("标杆值") ;
				}
				if(data.year[0]) {
					dataE.push(data.year[0].AvgFee) ;
					y.push("本期值") ;
				}
				// 图例边距和名称
				var legend = {"x":"40%","y":50, "data": ["次均费用"] } ;
				var param = {"title":data.year[0]==undefined ? "" : data.year[0].ccode+"病组次均费用对比图","subtitle":data.year[0].ddesc,
						"legend":legend,"series":[{"data":dataE,"name":"次均费用","type":"bar"}],"y":{"data":y}};
				// 网格上边距
				param.gridTop = 80 ;
				// 病组费用对比
				drawPayGroupBarChart("drgAvgFeeEch",param) ;
				// 病组费用构成
				processDrgFeeEchData (data) ;
				// 病组费用表格
				processAvgFeeAndFeeTabData(data) ;	
			}
		},param) ;
	}
}

/**
 * 
 * @@param data
 * @void
 * @ Discription: 处理费用构成echart图数据
 * @paygroupAnalysis_drg.js
 */
function processDrgFeeEchData (data) {
	var y = ["同期值","上期值","标杆值","本期值"] ;
	var techFee = [findQuotasVal(data,"year","TechFeecc"),findQuotasVal(data,"month","TechFeecc"),findQuotasVal(data,"std","TechFeecc"),findQuotasVal(data,"year","TechFee")] ;
	var manageFee = [findQuotasVal(data,"year","ManageFeecc"),findQuotasVal(data,"month","ManageFeecc"),findQuotasVal(data,"std","ManageFeecc"),findQuotasVal(data,"year","ManageFee")] ;
	var medFee = [findQuotasVal(data,"year","MedFeecc"),findQuotasVal(data,"month","MedFeecc"),findQuotasVal(data,"std","MedFeecc"),findQuotasVal(data,"year","MedFee")] ;
	var nursFee =[findQuotasVal(data,"year","NursFeecc"),findQuotasVal(data,"month","NursFeecc"),findQuotasVal(data,"std","NursFeecc"),findQuotasVal(data,"year","NursFee")] ;
	var drugMaterFee = [findQuotasVal(data,"year","DrugMaterFeecc"),findQuotasVal(data,"month","DrugMaterFeecc"),findQuotasVal(data,"std","DrugMaterFeecc"),findQuotasVal(data,"year","DrugMaterFee")] ;
	// 图例位置
	var legend = {"x":0,"y":50, "data": ["医疗费用", "护理费用","管理费用","医技费用","药品耗材费用"] } ;
	var param = {"title":data.year[0].ccode+"病组费用构成及对比图","subtitle":data.year[0].ddesc,"legend":legend,"series":[
	                                                              {"name":"医疗费用","type":"bar","data":medFee},
	                                                              {"name":"护理费用","type":"bar","data":nursFee},
	                                                              {"name":"管理费用","type":"bar","data":manageFee},
	                                                              {"name":"医技费用","type":"bar","data":techFee},
	                                                              {"name":"药品耗材费用","type":"bar","data":drugMaterFee}
	                                                              ],"y":{"data":y}};
	// 网格上边距
	param.gridTop = 80 ;
	// 病组费用构成
	drawPayGroupBarChart("drgFeeEch",param,null,"stackbar") ;
}
/**
 * 病组次均费用 费用构成及其对比情况表
 * @@param data
 * @void
 * @ Discription:
 * @paygroupAnalysis_drg.js
 */
function processAvgFeeAndFeeTabData(data){
	var columns=[
	               	{"data": "desc","title":"指标项"},
	               	{"data": "PayGroupCnt","title":"病例数",
	           			"render": function(obj, type, full) {
	           				if(full.desc == "标杆值") {
	           					return formatNumPayGroup(full.PayGroupCnt,"-") ;
	           				} 
	           				return formatNumPayGroup(full.PayGroupCnt,0) ;
	           			}
	               	},
	               	{"data": "PayGroupOverFeeCnt","title":"费用超标病例数",
	           			"render": function(obj, type, full) {
	           				if(full.desc == "标杆值") {
	           					return formatNumPayGroup(full.PayGroupOverFeeCnt,"-") ;
	           				}  
	           				return formatNumPayGroup(full.PayGroupOverFeeCnt,0) ;
	           			}
	               	},
	               	{"data": "AvgFee","title":"次均费用",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.AvgFee,2) ;
	           			}
	               	},
	           		{"data": "DrugFee","title":"药品费用",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.DrugFee,2) ;
	           			}
	               	},
	           		{"data": "DrugRatio","title":"药占比(%)",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.DrugRatio,2) ;
	           			}
	               	},
	           		{"data": "AvgDays","title":"平均住院日",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.AvgDays,0) ;
	           			}
	               	},
	           		{"data": "MedFee","title":"医疗费用",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.MedFee,2) ;
	           			}
	           		},
	           		{"data": "NursFee","title":"护理费用",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.NursFee,2) ;
	           			}
	           		},
	           		{"data": "ManageFee","title":"管理费用",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.ManageFee,2) ;
	           			}
	           		},
	           		{"data": "TechFee","title":"医技费用",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.TechFee,2) ;
	           			}
	           		},
	           		{"data": "DrugMaterFee","title":"药品耗材费用",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.DrugMaterFee,2) ;
	           			}
	           		} ,
	           		{"data": "operation","title":"操作",
	           			"render": function(obj, type, full,meta) {
	           				var str = "";
	           				
	           				if(meta.row==0)
           					{
	           					str = "<a class = 'costStructure' data-rowindex='"+meta.row+"'>费用构成</a>&nbsp;<a class=\"depA\" data-rowindex='"+meta.row+"'>科室</a>"
           					}
	           				else if(meta.row>=1)
           					{
	           					str = "<a class = 'costStructure' data-rowindex='"+meta.row+"'>费用构成</a>" ;
           					}
	           				return str;
	           			}
	           		}
     ];
	var dataTab = [] ;
	for(var i = 0 ; i<4 ; i++) {
		var value = {} ; 
		for(var o in columns) {
			// 指标编码
			var quotaCode = columns[o].data ;
			if(o == 0) {
				switch(i) {
					case  0 : value[quotaCode] = "本期值" ; break ;
					case  1 : value[quotaCode] = "标杆值" ; break ;
					case  2 : value[quotaCode] = "上期值" ; break ;
					case  3 : value[quotaCode] = "同期值" ; break ;
				}
			} else {
				switch(i) {
					case  0 : value[quotaCode] = findQuotasVal(data,"year",quotaCode) ; break ;
					case  1 : value[quotaCode] = findQuotasVal(data,"std",quotaCode+"cc") ; break ;
					case  2 : value[quotaCode] = findQuotasVal(data,"month",quotaCode+"cc") ; break ;
					case  3 : value[quotaCode] = findQuotasVal(data,"year",quotaCode+"cc") ; break ;
				}
			}
		}
		dataTab.push(value) ;
	}
	var drgCode = data.year[0] == undefined ? "" : data.year[0].ccode ;
	var paramsDataTables={searching:false,lengthChange:false,ordering:false,stateSave:true,info:false,paging:false,tableTitle:drgCode +"病组次均费用、费用构成及对比情况表",columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
	var table = $("#"+tabId+" #avgFeeAndFeeTab").dataTableBasic(columns,dataTab,paramsDataTables) ;
	$("#"+tabId+" #avgFeeAndFeeTab_wrapper caption").html("<h5>"+drgCode + "病组次均费用、费用构成及对比情况表"+"</h5>") ;
	$('#'+tabId+' #avgFeeAndFeeTab tr a.costStructure').on( 'click',function () {
    	var index = $(this).attr("data-rowindex");
    	var a = table.row( index ).data();//本期|同期|上期
    	var b = table.row(1).data();//标杆
    	var c = ["desc","MedFee","NursFee","ManageFee","TechFee","DrugMaterFee","AvgFee"];
    	costStructure(a,b,c);
    } );
	$("#"+tabId+" #avgFeeAndFeeTab").on("click",".depA",function(){
		var index = $(this).attr("data-rowindex");
    	var target = table.row(1).data();//标杆
		var param = drgUI.setAjaxData(tabId);
		param.pType = "1" ;
		param.target = target;
		param.pardrgCode = drgCode ;
		var pid = target+drgCode ;
		openTab("/pages/paygroup/paygroupAnalysis_dep.jsp",  drgCode +"|病组费用分析", "paygroupAnalysis_dep.jsp"+pid , "paygroupAnalysis_dep.jsp"+pid, param);
	})
	
	//超标颜色变红
	for(var c = 4;c<=12;c++)
	{//从第4列 到第12列 (开始为1)
		for(var r=1;r<=4;r++)
		{//从第1行 到第4行 (开始为1)
			if(r==2)
			{
				continue;//标杆行
			}
			var cv = $("#"+tabId+" #avgFeeAndFeeTab tr:nth-child("+r+") td:nth-child("+c+")").text();//列值
			var tv = $("#"+tabId+" #avgFeeAndFeeTab tr:nth-child("+2+") td:nth-child("+c+")").text();//标杆值
			if(transformFloat(cv)>transformFloat(tv))
			{
				$("#"+tabId+" #avgFeeAndFeeTab tr:nth-child("+r+") td:nth-child("+c+")").css("color","red");
			}
		}
	}
}


/**
 * 访问某个指标的比较值。比如 次均费用的标杆值  data[std][AvgFee]
 * @@param data
 * @@param compareType 
 * @@param quotaCode
 * @@param flag 是否是累计值
 * @@returns
 * @any
 * @ Discription:
 * @paygroupAnalysis_drg.js
 */
function findQuotasVal(data,compareType,quotaCode) {
	if(data[compareType][0] && data[compareType][0][quotaCode]) {
		if(isNaN(data[compareType][0][quotaCode])){
			return data[compareType][0][quotaCode] ;
		} else {
			return Number(data[compareType][0][quotaCode]) ;
		}
		
	} else {
		return "" ;
	}
}

/**
 * 全院指标
 * @@param thisObj
 * @void
 * @ Discription:
 * @paygroupAnalysis.js
 */
function loadCntDrgDiv(thisObj) {
	var container = $("#" +tabId+" #"+thisObj.id+"") ;
	container.find(".title28").html(thisObj.title);
	var str = "";
	for(var o in thisObj.quotas) {
		str+="<div class=\"row-fluid clearfix contotalcq2\" >"  ;
		str+="<div class=\"col-md-6\">"+thisObj.quotas[o].title+"</div>"  ;
		str+="<div class=\"col-md-6\">"  ;
		if(thisObj.quotas[o].code.indexOf("|") > 0) {
			var quota = thisObj.quotas[o].code.split("|") ;
			var value = "" ;
			if(thisObj.data.drgs[0] && thisObj.data.drgs[0][quota[0]] && thisObj.data.drgs[0][quota[1]]) {
				//算比率 比率是由两个指标计算得到
				value = (thisObj.data.drgs[0][quota[0]]/thisObj.data.drgs[0][quota[1]]*100).toFixed(2) ;
			} else if(thisObj.data.drgs[0] && thisObj.data.drgs[0][quota[0]+"cc"]) {
				//第二个指标代码为空  拿该指标的 标杆值
				value = thisObj.data.drgs[0][quota[0]+"cc"];
			} else if(thisObj.data.drgs[0] && !thisObj.data.drgs[0][quota[0]]) {
				value = 0 ;
			}
			str+="<span class=\"number\" style=\"text-align: right;padding-right: 10px;\">"+value+"</span>"  ;
		} else {
			if(thisObj.quotas[o] && thisObj.data.drgs[0] && thisObj.data.drgs[0][thisObj.quotas[o].code]) {
				if(thisObj.quotas[o].link)
				{
					str+="<span class=\"number\" style=\"text-align: right;padding-right: 10px;\"><a href=\"javascript:"+thisObj.quotas[o].link+"()\">"+ thisObj.data.drgs[0][thisObj.quotas[o].code] +"</a></span>"  ;
				}
				else
				{
					str+="<span class=\"number\" style=\"text-align: right;padding-right: 10px;\">"+ thisObj.data.drgs[0][thisObj.quotas[o].code]+"</span>"  ;
				}
				
			} else {
				str+="<span class=\"number\" style=\"text-align: right;padding-right: 10px;\">0</span>"  ;
			}   
		}
		str+="</div>"  ;
		str+="</div>"  ;
	}
	container.find(".ci").html(str) ;
}


//不同区间内病例费用构成及对比 参数调整
function ajustBenchParam() {
	$("#"+tabId+" #benchmarkSlider,#stdDeviationSlider").toggle() ;
	
}


/**
 * 获取最小值  最大值  中位数
 * @
 * @void
 * @ Discription:
 * @paygroupAnalysis_drg.js
 */
function findFeeExtremal() {
	var param = paramTabPage[tabId]= $("#tabContent > .tab-pane.active").data() ;
	param.pType = "1" ;
	$.post(contextPath + "/payGroup/findFeeExtremal.dhc", param ).done(function(data) {
		var container = $("#" +tabId+" #caseFee") ;
		var data = data.data[0] ;
		container.children(":eq(0)").children(":eq(1)").text(data.MINVAL) ;
		container.children(":eq(1)").children(":eq(1)").text(data.MEDIANCAL) ;
		container.children(":eq(2)").children(":eq(1)").text(data.MAXVAL) ;
	})
}
/**
 * 病例分布特征
 */
function findCaseDistributionFeature(){
	$(document).bind("click",function(e){
       var target = $(e.target); 
       if(target.closest("#caseDistriParamDiv").length != 0){ 
           $('#'+tabId+' #caseDistriParamNav').addClass("open");
       }else{
    	   $('#'+tabId+' #caseDistriParamNav').removeClass("open"); 
       }
	});
	
	//判断监测时间是否为自定义，如果监测时间类型为自定义，参数范围默认选择本期
	if($("#searchcq").children().eq(2).find("div.ci a").eq(2).hasClass("active")){
		$('#'+tabId+' .caseDistriParamType').find("a").removeClass("active");
		$('#'+tabId+' .caseDistriParamType').find("a").eq(2).addClass("active");
	}
	//条件选择框点击事件
	$('#'+tabId+' #caseDistriParamDiv').off('click','a');
	$('#'+tabId+' #caseDistriParamDiv').on('click','a',function(){
		if($(this).attr('data-type')=="intervalCustom"){
			 $(this).css("display","none");
			 $('#'+tabId+' #intervalCustom').css("display","inline-block");
		 }
		 else if($(this).closest(".caseDistriParamInterval").length>0){
			 $('#'+tabId+' #intervalCustom').css("display","none");
			 $('#'+tabId+' #intervalCustom').prev().css("display","inline");
		 }
		//如果监测时间类型为自定义，参数范围只允许选择本期
		if($("#searchcq").children().eq(2).find("div.ci a").eq(2).hasClass("active")&&$(this).closest(".caseDistriParamType").length>0){
			$('#'+tabId+' ."caseDistriParamType"').find("a").removeClass("active");
			$('#'+tabId+' ."caseDistriParamType"').find("a").eq(2).addClass("active");
		}
		else{
			$(this).parent().find("a").removeClass("active");
			$(this).addClass("active");
		}
	});
	//区间个数input修改事件
	$('#'+tabId+' #intervalCustom').on('change','#intervalCustomInput',function(){
		$('#'+tabId+' .caseDistriParamInterval [data-type="intervalCustom"]').attr('data-value',$(this).val());   
	});
	
	var param = drgUI.setAjaxData(tabId) ;
	param.pType = "1" ;
	param.normalParam=$('#'+tabId+' .caseDistriParamType a.active').attr('data-value');
	param.interval=$('#'+tabId+' .caseDistriParamInterval a.active').attr('data-value');
	if(param.interval==""){
		drgUI.error('请指定区间个数参数!');
		return;
	}
	echartLoadingInit($('#'+tabId+' #probabilityDisEch'));
	echartLoadingInit($('#'+tabId+' #cumulativeDisEch'));
	$.post(contextPath + "/payGroup/getNormalDistributionData.dhc", param).done(function(result) {
		var data=result.data;
		var category=data.category;
		var axisCategory = jQuery.extend(true, [],category);
		axisCategory.pop();//移除最后一个元素
		var caseCnt=data.intervalFrequency;
		var cumulativeData=data.cumulativeDistribution;
		var probilityData=data.probilityDensity;
		var legend='';
		var xAxis = [{type : 'category',data : axisCategory}];
		var yAxis = [{type : 'value',name : '病例数',splitNumber:5},
			        {type : 'value',name : '累积占比(%)',splitLine:{show:false}}];
		var series = [
				        {name:'病例数',type:'bar',data:caseCnt},
				        {name:'累积占比(%)',type:'line',yAxisIndex: 1,data:cumulativeData,smooth:true}
				    ];
		var chartParams={autoWidth:true,autoHeight:'auto',heightRatio:0.6,gridTop:80,gridBottom:20,gridRight:'12%',gridLeft:30};
		chartParams.formatterFunc=function (params) {
			var str=category[params[0].dataIndex]+"~"+category[params[0].dataIndex+1]+ "<br/>";
        	for(var o in params){
        		if(params[o].data!=null){
        			str+=params[o].seriesName+":"+params[o].data+ "<br/>";
        		}
        	}
        	return str;
    	};
		barLineMixChartBasic($('#'+tabId+' #cumulativeDisEch'), legend,series,xAxis,yAxis,param.pardrgCode+'病组下病例住院费用直方图及正态累积分布图',paramTabPage[tabId].desc.substring(5),chartParams);
		
		//概率密度
		var xAxisP = [{type : 'category',data : axisCategory}];
		var yAxisP = [{type : 'value',name : '病例数',splitNumber:5},
			        {type : 'value',name : '概率密度',splitLine:{show:false}, axisLabel : {formatter: function (value, index) {return Number(value).toExponential(2);}}}];
		var seriesP = [
				        {name:'病例数',type:'bar',data:caseCnt},
				        {name:'正态分布概率密度',type:'line',yAxisIndex: 1,data:probilityData,smooth:true}
				    ];
		var chartParamsP={autoWidth:true,autoHeight:'auto',heightRatio:0.6,gridTop:80,gridBottom:20,gridRight:'12%',gridLeft:30};
		//提示框处理函数
		chartParamsP.formatterFunc=function (params) {
			var str=category[params[0].dataIndex]+"~"+category[params[0].dataIndex+1]+ "<br/>";
        	for(var o in params){
        		if(params[o].seriesName=="正态分布概率密度"){
        			str+=params[o].seriesName+":"+Number(params[o].data).toExponential(2)+ "<br/>";
        		}
        		else{
        			str+=params[o].seriesName+":"+params[o].data+ "<br/>";
        		}
        		
        	}
        	return str;
    	};
		barLineMixChartBasic($('#'+tabId+' #probabilityDisEch'), legend,seriesP,xAxisP,yAxisP,param.pardrgCode+'病组下病例住院费用直方图及正态分布概率密度曲线',paramTabPage[tabId].desc.substring(5),chartParamsP);
		//参数调整框隐藏
		$('#'+tabId+' #caseDistriParamNav').removeClass("open");
	});
}
